#include "GCString.h"
#include "GCData.h"


namespace gcstock
{
    OUT GCFLOAT power(IN const GCFLOAT x, IN const GCINT y)
    {
        GCFLOAT tmp = x;
        if(y == 0)
        {
            return 1.0f;
        }

        if(y == 1)
        {
            return x;
        }
        for(GCINT i = 2;i < y; ++i)
        {
            tmp = tmp * tmp;
        }
        return tmp;
    }
    OUT GCFLOAT GCFloat::fromStrToFloat(IN const GCCHAR* str)
    {
        int idx = GCFind(str,_GCT('.'));
        GCCHAR* endPtr = NULL;
        GCCHAR* startPtr = NULL;
        int integer = GCSTRTOL(str,&endPtr,10);    
        if(*endPtr == _GCT('.'))
        {
            startPtr = endPtr++;
            GCFLOAT decimal = GCSTRTOL(endPtr, &endPtr, 10);
            int delta = endPtr - startPtr;
            decimal = decimal / (power(10.0f,(endPtr - startPtr)) );
            return (GCFLOAT)integer + decimal;
        }
        else
        {
            return integer;
        }
        return 0;
    }
}